#include <stdio.h>
#include "view.h"
#include "util_picture.h"

#define FONT_PATH1 "../../resource/font/Droid_Sans_Fallback.ttf"
#define FONT_PATH2 "../../resource/font/ZhanKuXiaoLOGOTi-2.otf"

void Test_Show(View* v);
void Test_Api_OnCallback(View* v);

View* ViewInit()
{
    View* root = new View();

    /* 根控件 : 开辟 300 x 300 屏幕 */
    ViewInfo info("root", 300, 200);
    info.shapeColor = 0xFFFFFF;
    root->m_info = info;

    /* 子控件1 : 自动宽,自动高,横纵向居中于父控件 */
    info.Reset("sub1", VRS_AUTO, VRS_AUTO, 0, VRT_CENTER_X | VRT_CENTER_Y);
    info.shapeColor = 0xFF0000;
    info.text = Value("12345\r\n67890");
    info.textSize = 24;
    info.textSpaceX = 0;
    info.textSpaceY = 0;
    root->ChildAdd(info);

    /* 子控件2 : 自动宽,高一致,相对于上一控件,在对象正下方 */
    info.Reset("sub2", VRS_AUTO, VRS_MATCH, VRO_PREV, VRT_BOTTOM | VRT_CENTER_X);
    info.shapeColor = 0x00FF00;
    info.text = Value("啊这");
    info.textSize = 24;
    info.textMarginLeft = 10;
    info.textMarginRight= 10;
    root->ChildAdd(info);

    return root;
}

int main()
{
    Image image(300, 300);
    View* v = ViewInit();

    View::FontLoad(VFT_DEFAULT, FONT_PATH1);
    View::FontLoad(VFT_ZK_LOGO, FONT_PATH2);

    Test_Api_OnCallback(v);

    v->Render(&image);
    UtilPicCreate("./out.screen.png", &image);

    Test_Show(v);

    delete v;
    return 0;
}

void Test_Show(View* v)
{
    printf("root: %s: %d,%d %dx%d \r\n",
        v->m_info.name.c_str(),
        v->GetX(),
        v->GetY(),
        v->GetWidth(),
        v->GetHeight());

    printf("child: \r\n");
    for (View* cv = v->ChildBegin(); cv; cv = cv->Next())
    {
        printf("  %s: %d,%d %dx%d \r\n",
            cv->m_info.name.c_str(),
            cv->GetX(),
            cv->GetY(),
            cv->GetWidth(),
            cv->GetHeight());
    }
}

void Test_Api_OnCallback(View* v)
{
    printf("VCT_CLICLK[0, 0]: %d \r\n", (int32_t)v->OnCallback(VCT_CLICLK, 0, 0));
}
